﻿using System.Collections.Generic;
using Compass.Wasm.Shared;

namespace Compass.Wpf.ApiServices.Plans;

public interface IPackingItemService : IBaseService<PackingItemDto>
{
    Task<ApiResponse<PackingItemDto>> AddPalletAsync(PackingItemDto dto);
    Task<ApiResponse<PackingItemDto>> UpdatePalletAsync(Guid id, PackingItemDto dto);
    Task<ApiResponse<PackingItemDto>> UpdatePalletNumberAsync(Guid id);
    Task<ApiResponse<List<PackingItemDto>>> GetAllByMainPlanIdAsync(Guid mainPlanId);
}

public class PackingItemService : BaseService<PackingItemDto>, IPackingItemService
{
    private readonly HttpRestClient _client;
    private const string ServiceName ="PackingItem";
    public PackingItemService(HttpRestClient client) : base(client, ServiceName)
    {
        _client = client;
    }

    public async Task<ApiResponse<PackingItemDto>> AddPalletAsync(PackingItemDto dto)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Post,
            Route = $"api/{ServiceName}/AddPallet",
            Param = dto
        };
        return await _client.ExecuteAsync<PackingItemDto>(request);
    }
    public async Task<ApiResponse<PackingItemDto>> UpdatePalletAsync(Guid id, PackingItemDto dto)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Put,
            Route = $"api/{ServiceName}/Pallet/{id}",
            Param = dto
        };
        return await _client.ExecuteAsync<PackingItemDto>(request);

    }
    public async Task<ApiResponse<PackingItemDto>> UpdatePalletNumberAsync(Guid id)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Put,
            Route = $"api/{ServiceName}/PalletNumber/{id}",
            Param = new object()
        };
        return await _client.ExecuteAsync<PackingItemDto>(request);

    }

    public async Task<ApiResponse<List<PackingItemDto>>> GetAllByMainPlanIdAsync(Guid mainPlanId)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/PackingList/{mainPlanId}"
        };
        return await _client.ExecuteAsync<List<PackingItemDto>>(request);
    }
}